﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace DAL
{
    public class UserDal : IDAL.IUserDal
    {
        string constr = ConfigurationManager.ConnectionStrings["constr"].ToString();
        public int userReegister(MODEL.User m)
        {
            using (SqlConnection con = new SqlConnection("Data Source=LAPTOP-RBEAC1QO\\SQLSERVER;Initial Catalog=dsmanager;Integrated Security=True"))
            {
                con.Open();
                SqlCommand com = new SqlCommand("Register", con);
                com.CommandType = CommandType.StoredProcedure;
                SqlParameter[] p ={
                               new SqlParameter("@name",SqlDbType.VarChar,200),
                               new SqlParameter("@pwd",SqlDbType.VarChar,200),
                               new SqlParameter("@tel",SqlDbType.VarChar,200),
                           };
                p[0].Value = m.email;
                p[1].Value = m.upwd;
                p[2].Value = m.utel;
                com.Parameters.AddRange(p);
                var i = com.ExecuteNonQuery();
                return i;
            }
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int userLogin(MODEL.User m)
        {
            using (SqlConnection con = new SqlConnection("Data Source=LAPTOP-RBEAC1QO\\SQLSERVER;Initial Catalog=dsmanager;Integrated Security=True"))
            {
                con.Open();
                SqlCommand com = new SqlCommand("loginhr", con);
                com.CommandType = CommandType.StoredProcedure;
                SqlParameter[] p ={
                               new SqlParameter("@Name",SqlDbType.VarChar,200),
                               new SqlParameter("@pwd",SqlDbType.VarChar,200),
                           };
                p[0].Value = m.email;
                p[1].Value = m.upwd;
                com.Parameters.AddRange(p);
                var i = com.ExecuteScalar();
                return (int)i;
            }
        }
        /// <summary>
        /// 查找密码是否错误
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public int userselid(string upwd)
        {
            using (SqlConnection con = new SqlConnection("Data Source=LAPTOP-RBEAC1QO\\SQLSERVER;Initial Catalog=dsmanager;Integrated Security=True"))
            {
                con.Open();
                SqlCommand com = new SqlCommand("chasel", con);
                com.CommandType = CommandType.StoredProcedure;
                SqlParameter[] p ={
                                     new SqlParameter("@name",SqlDbType.VarChar,200),
                                 };
                p[0].Value = upwd;
                com.Parameters.AddRange(p);
                var i = com.ExecuteScalar();
                return (int)i;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int userupdate(MODEL.User m)
        {
            using (SqlConnection con = new SqlConnection("Data Source=LAPTOP-RBEAC1QO\\SQLSERVER;Initial Catalog=dsmanager;Integrated Security=True"))
            {
                con.Open();
                SqlCommand com = new SqlCommand("upt", con);
                com.CommandType = CommandType.StoredProcedure;
                SqlParameter[] p ={
                                     new SqlParameter("@pwd",SqlDbType.VarChar,200),
                                     new SqlParameter("@pwd1",SqlDbType.VarChar,200),
                                 };
                p[0].Value = m.upwd

                    ;
                p[1].Value = m.upwd1;
                com.Parameters.AddRange(p);
                var i = com.ExecuteNonQuery();
                return i;
            }
        }

        public int add(MODEL.User model)
        {
            throw new NotImplementedException();
        }

        public List<MODEL.User> show()
        {
            throw new NotImplementedException();
        }

        public int del(int id)
        {
            throw new NotImplementedException();
        }

        public MODEL.BaseModel updid(int id)
        {
            throw new NotImplementedException();
        }

        public int upd(MODEL.User model)
        {
            throw new NotImplementedException();
        }
    }
}
